//    Openbravo POS is a point of sales application designed for touch screens.
//    Copyright (C) 2007-2009 Openbravo, S.L.
//    http://www.openbravo.com/product/pos
//
//    This file is part of Openbravo POS.
//
//    Openbravo POS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Openbravo POS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Openbravo POS.  If not, see <http://www.gnu.org/licenses/>.

package com.openbravo.bean.shard;

/**
 *
 * @author adrianromero
 */
public class MovementReason{
	
	public static final String NULL="";
	public static final String IN_PURCHASE="stock.in.purchase";
	public static final String IN_REFUND="stock.in.refund";
	public static final String IN_MOVEMENT="stock.in.movement";
	public static final String OUT_SALE="stock.out.sale";
	public static final String OUT_REFUND="stock.out.refund";
	public static final String OUT_BREAK="stock.out.break";
	public static final String OUT_MOVEMENT="stock.out.movement";
	public static final String OUT_CROSSING="stock.out.crossing";
	
	public static final String IN_POS="POS+";
	public static final String OUT_POS="POS-"; 
   
	
	public static final String[] IN=new String[]{
		IN_PURCHASE,IN_REFUND,IN_MOVEMENT
	};
	
	public static final String[] OUT=new String[]{
		OUT_SALE,OUT_REFUND,OUT_BREAK,OUT_MOVEMENT,OUT_CROSSING
	};
	   
    
    public static boolean isInput(String value) {
    	for(String val:IN){
    		if(val==value)
    			return true;
    	}
        return false;
    }

    public static Double samesignum(String value,Double d) {
        
        if (d == null || value == null) {
            return d;
        } else if ((isInput(value)&& d.doubleValue() < 0.0) || (!isInput(value) && d.doubleValue() > 0.0)) {
            return new Double(-d.doubleValue());
        } else {
            return d;
        }   
    }    
    
    public static Double getPrice(String value,Double dBuyPrice, Double dSellPrice) {
        
        if (value == IN_PURCHASE || value == OUT_REFUND || value == OUT_BREAK) {
            return dBuyPrice;
        } else if (value == OUT_SALE || value == IN_REFUND) {
            return dSellPrice;
        } else {
            return null;
        }
    }
}
